<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue计算属性</title>
</head>
<body>
    <div id="app">
        <!-- {{fullName}}
        {{fullName2()}} -->
        {{fullName}}
        {{age}}
    </div>
</body>
<script src="vue.js"></script>
<script>

    var vm = new Vue({
        el: '#app',
        data: {
            firstName: 'Dell',
            lastName: 'Lee',
            fullName: '',
            age: 24
        },
/*         computed: {
            fullName() {
                console.log('计算了fullName一次')
                return this.firstName +' '+ this.lastName;
            },
            now() {
                return Date.now(); 
            }
        },
        methods: {
            fullName2() {
                console.log('方法fullName2调用了一次')
                return this.firstName +' '+ this.lastName;
            }
        } */

        watch: {
            firstName() {
                console.log('first计算了一次')
                this.fullName = this.firstName + ' ' + this.lastName;
            },
            lastName() {
                console.log('last计算了一次')
                this.fullName = this.firstName + ' ' + this.lastName;
            }
        }
    })
</script>
</html>